﻿using LinFu.IoC.Interfaces;

namespace CoreEx.Common.Ioc
{
    /// <summary>
    /// Base class for implementing pre processors
    /// </summary>
    /// <typeparam name="TServiceType">The service type that this <see cref="PreProcessorBase{TServiceType}"/> applies to.</typeparam>
    public abstract class PreProcessorBase<TServiceType> : IPreProcessor
    {
        #region IPreProcessor Members

        ///<summary>       
        /// Allows a <see cref="T:LinFu.IoC.Interfaces.IPostProcessor" /> instance
        /// to inspect or modify the result of a service request
        /// just before the service is instantiated.           
        ///</summary>
        ///<seealso cref="T:LinFu.IoC.Interfaces.IServiceRequestResult" />
        ///<param name="request">The <see cref="T:LinFu.IoC.Interfaces.IServiceRequest" /> instance that describes the nature of the service that needs to be created. </param>
        public void Preprocess(IServiceRequest request)
        {
            if (request.ServiceType == typeof(TServiceType))
                Process(request);
        }

        /// <summary>
        /// Performs the actual processing.
        /// </summary>
        /// <remarks>
        /// This method is only called of the service type matches the type of <typeparamref name="TServiceType"/>
        /// </remarks>
        /// <param name="request">An <see cref="IServiceRequest"/> instance that contains information about the service request.</param>
        public abstract void Process(IServiceRequest request);        
       
        #endregion
    }
}